package ljl.alg.jianzhioffer.round3.easy;

import commons.ListNode;

public class _22_getKthFromEnd {

    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode fast = head, slow = head;
        while (k-- > 0 && fast != null)
            fast = fast.next;
        if (k > 0)
            return null;
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        return slow;
    }

}
